package com.day24.Reflect01;


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo01 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        Class<?> c=Class.forName("com.day24.ClassLoader.Student");
        Field[] fields=c.getDeclaredFields();
        for(Field f:fields){
            System.out.println(f);
        }
        System.out.println("---------");
        Field addressField=c.getField("address");
        Constructor<?> con=c.getConstructor();
        Object obj=con.newInstance();
        addressField.set(obj,"北京");
        System.out.println(obj);
    }
}
